﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using System.Collections.Specialized;

namespace LightSwitchApplication
{
    public partial class AdvanceEmployeesEditGrid
    {
        partial void WcfAdvanceEmployees_Changed(NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (var item in e.NewItems)
                {
                    if (item is WcfAdvanceEmployee)
                    {
                        (item as WcfAdvanceEmployee).DocumentDate = this.DocumentDate;
                        (item as WcfAdvanceEmployee).ReasonID = this.ReasonID == null ? null : this.ReasonID.ReasonID;
                    }
                }
            }
        }

        partial void AdvanceEmployeesEditGrid_Created()
        {
            // Write your code here.
            this.DocumentDate = DateTime.Now;
        }

        partial void AdvanceEmployeesEditGrid_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            // Write your code here.
            saveChangesTo.Add(this.DataWorkspace.LSWData);
            saveChangesTo.Add(this.DataWorkspace.wcfServiceData);
        }

        partial void AdvanceEmployeesEditGrid_Saving(ref bool handled)
        {
            // Write your code here.
            this.DataWorkspace.LSWData.SaveChanges();
            this.DataWorkspace.wcfServiceData.SaveChanges();
            this.Close(false); 
            handled = true;
        }
    }
}
